package cn.edu.sdjzu.knoverse.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.edu.sdjzu.knoverse.model.dto.system.router.AssignRolesToRoutersDto;
import cn.edu.sdjzu.knoverse.model.vo.result.Result;
import  cn.edu.sdjzu.knoverse.service.RouterRoleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 路由和角色
 */
@Tag(name = "路由和角色", description = "路由和角色相关接口")
@RestController
@RequestMapping("/routerRole")
public class RouterRoleController {

    @Autowired
    private RouterRoleService routerRoleService;

    @SaCheckPermission("routerRole::getRoleListByRouterId")
    @Operation(summary = "根据菜单id获取所有角色", description = "根据菜单id获取所有角色")
    @GetMapping("getRoleListByRouterId")
    public Result<List<String>> getRoleListByRouterId(Long routerId) {
        List<String> roleListByRouterId = routerRoleService.getRoleListByRouterId(routerId);
        return Result.success(roleListByRouterId);
    }

    @SaCheckPermission("routerRole::assignRolesToRouter")
    @Operation(summary = "为菜单分配角色", description = "为菜单分配角色")
    @PostMapping("assignRolesToRouter")
    public Result<String> assignRolesToRouter(@RequestBody AssignRolesToRoutersDto dto) {
        routerRoleService.assignRolesToRouter(dto);
        return Result.success();
    }

    @SaCheckPermission("routerRole::assignAddBatchRolesToRouter")
    @Operation(summary = "批量为菜单添加角色", description = "批量为菜单添加角色")
    @PostMapping("assignAddBatchRolesToRouter")
    public Result<String> assignAddBatchRolesToRouter(@RequestBody AssignRolesToRoutersDto dto) {
        routerRoleService.assignAddBatchRolesToRouter(dto);
        return Result.success();
    }

    @SaCheckPermission("routerRole::clearAllRolesSelect")
    @Operation(summary = "清除选中菜单所有角色", description = "清除选中菜单所有角色")
    @DeleteMapping("clearAllRolesSelect")
    public Result<String> clearAllRolesSelect(@RequestBody List<Long> routerIds) {
        routerRoleService.clearAllRolesSelect(routerIds);
        return Result.success();
    }
}
